﻿using System;

class GuessNumberGame
{
    static void Main(string[] args)
    {
        Random random = new Random();
        int totalScore = 0; // 总积分
        bool playAgain = true;

        Console.WriteLine("欢迎来到猜数字游戏！");
        Console.WriteLine("每次猜中数字都会获得5分，积分会累计。");

        while (playAgain)
        {
            int targetNumber = random.Next(1, 101); // 生成1到100的随机数
            int attempts = 0;
            bool hasGuessedCorrectly = false;

            Console.WriteLine("\n新的一轮游戏开始！我已经生成了一个1到100之间的数字。");

            while (!hasGuessedCorrectly)
            {
                Console.Write("请输入你的猜测：");
                string input = Console.ReadLine();

                if (!int.TryParse(input, out int guess))
                {
                    Console.WriteLine("请输入一个有效的整数！");
                    continue;
                }

                attempts++;

                if (guess < targetNumber)
                {
                    Console.WriteLine("太小了，再试一次！");
                }
                else if (guess > targetNumber)
                {
                    Console.WriteLine("太大了，再试一次！");
                }
                else
                {
                    hasGuessedCorrectly = true;
                    totalScore += 5; // 猜中一次增加5分

                    Console.WriteLine($"恭喜你，猜对了！你用了{attempts}次尝试。");
                    Console.WriteLine($"本轮获得积分：5，总积分：{totalScore}");

                    Console.Write("是否继续游戏？(y/n): ");
                    string choice = Console.ReadLine().ToLower();

                    if (choice != "y")
                    {
                        playAgain = false;
                        Console.WriteLine("游戏结束，感谢参与！");
                    }
                }
            }
        }
    }
}